home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / edit / amis.lha / amis / viewers / sources / Viewer.h < prev    next >
C/C++ Source or Header  |  1996-12-30  |  14KB  |  512 lines

  1. /*
  2.     AMIS Include for Viewers. (V1.01)
  3.  
  4.     In this file you almost everything you need to create you own viewer.
  5.     This file is still under development, see later versions for a more
  6.     complete documentation.
  7. */
  8.  
  9. struct LineInfo
  10. {
  11.     short    li_length;                /* Don't change this !! */
  12.     short    li_height;                /* For more information see the Viewer
  13.                                             structure. */
  14.     long    li_viewerdata;            /* This is for you... */
  15.     long    li_viewerdata2;        /* and so is this... */
  16. };
  17.  
  18. struct EditWin
  19. {
  20.     long    wn_next;
  21.     long    wn_prev;
  22.     char    wn_type;
  23.     char    wn_pri;
  24.     long    wn_name;
  25.     struct Window    *wn_base;
  26.     struct RastPort    *wn_rast;
  27.     long    wn_gadget;
  28.     short    wn_innerwidth;
  29.     short    wn_innerheight;
  30.     short    wn_left;
  31.     short    wn_top;
  32.  
  33.     long    *ed_memlist;
  34.     long    *ed_project;
  35.     struct Font    *ed_font;
  36.     struct Viewer    *ed_display;
  37.     long    ed_bookmarks[10];
  38.     long    ed_viewerdata;                    /* This is for you  */
  39.     long    ed_moreviewerdata[16];        /* and so is this   */
  40.     long    ed_viewervar[10];                /* and some more    */
  41.     long    ed_viewerobj;                    /* and this one too */
  42.     char    ed_flags;
  43.     char    ed_flags2;
  44.     char    ed_flags3;
  45.     char    ed_flags4;
  46.     char    ed_flags5;
  47.     char    ed_flags6;
  48.     char    ed_protectflags;
  49.     char    ed_moreflags;
  50.     long    ed_clip;
  51.     short    ed_tabsize;
  52.     long    ed_winchars;
  53.     long    ed_winlines;
  54.     short    ed_top_offset;
  55.     short    ed_pl_y_offset;
  56.     short    ed_pl_own_height;
  57.     long    ed_pl_total_y;
  58.     short    ed_bordertop;
  59.     short    ed_first_y;
  60.     short    ed_last_y;
  61.     long    ed_visible_y;
  62.     long    ed_topline;
  63.     long    ed_topline_tick;
  64.     long    ed_leftchar;
  65.     long    ed_lines;
  66.     long    ed_chars;
  67.     long    ed_line;
  68.     long    ed_oldtopline;
  69.     long    ed_oldtoppos;
  70.     struct LineInfo    *ed_linesinfo;
  71.     char    *ed_buffer;                            /* the text of this file */
  72.     long    ed_bufsize;
  73.     long    ed_bufpos;
  74.     char    *ed_linebuf;                        /* this lines text */
  75.     char    *ed_linebuf_backup;
  76.     long    ed_linebuflast;
  77.     long    ed_oldlinelength;
  78.     long    ed_char;
  79.     long    ed_winpos;
  80.     long    ed_cursoffset;
  81.     short    ed_curs_px1;
  82.     short    ed_curs_py1;
  83.     short    ed_curs_px2;
  84.     short    ed_curs_py2;
  85.     short    ed_buttonwidth;
  86.     void    *ed_buttonlist;
  87.     long    ed_slidertopline;
  88.     long    ed_sliderlines;
  89.     short    ed_slidersize;
  90.     long    ed_startpos;
  91.     long    ed_endpos;
  92.     long    ed_last_startpos;
  93.     long    ed_last_endpos;
  94.     long    ed_oldline;
  95.     long    ed_oldchar;
  96.     long    ed_mouseline;
  97.     long    ed_mousechar;
  98.     long    ed_mousepos;
  99.     long    ed_blocktemp1;
  100.     long    ed_blocktemp2;
  101.     long    ed_blocktemp3;
  102.     long    ed_blocktemp4;
  103.     long    ed_subpos;
  104.     short    ed_viewerbar_y;
  105.     long    ed_removefunc;
  106.     short    ed_statusbar_y;
  107.     short    ed_codebar_y;
  108.     short    ed_freebar;
  109.     long    ed_title_msg;
  110.     short    ed_tm_time;
  111.     long    ed_timerioreq;
  112.     short    ed_lineheight;
  113.  
  114.     char    ed_path[144];
  115.     char    ed_filename[144];
  116.     char    ed_name[144];
  117.     char    ed_screenname[100];
  118.     char    ed_comment[80];
  119.  
  120. /* PRIVATE !! */
  121.  
  122.     long    ed_tmprastport;
  123.     long    ed_tmplayer;
  124.     long    ed_tmpbitmap;
  125.     long    ed_layerinfo;
  126.  
  127.     struct List    ed_linelist;
  128. };
  129.  
  130. struct Viewer
  131. {
  132.     struct Node        vw_node;                /* Fill in the name and set ln_type to
  133.                                                     the version of AMIS this viewer was
  134.                                                     made for. (See Versions below). */
  135.     long    vw_loadseg;                        /* Set to zero! */
  136.  
  137. /*
  138.     With the next three options you can tell AMIS for which files this viewer
  139.     should be used. Note that the file must have all three before it will be
  140.     recognized. You can set starttext and typicaltext to zero if neccessery.
  141. */
  142.  
  143.     char    *vw_filepattern;                /* filepattern, e.g. "#?" */
  144.     char    *vw_starttext;                    /* first text in file, e.g. "@database"*/
  145.     char    *vw_typicaltext;                /* some text somewhere in every file of
  146.                                                     your type, e.g. "@node" */
  147.  
  148.     void    (*vw_switchfunction)();        /* function to be called after every
  149.                                                     switch to this viewer */
  150.  
  151.     char    vw_flags1;                        /* flags for you, see below */
  152.     char    vw_flags2;                        /* AMIS private flags ! */
  153.  
  154.     void    (*vw_display)();                /* the display function it self */
  155.     void    (*vw_newpos)();                /* function to be called every time the
  156.                                                     cursor is moved */
  157.     void    (*vw_getwinpos)();            /* return winpos when char is given */
  158.     void    (*vw_getchar)();                /* return char when winpos is given */
  159.     void    (*vw_codebar)();                /* return text to be displayed in
  160.                                                     codebar */
  161.  
  162. /*
  163.     With the following three options you can change the height of the text
  164.     lines. First textheights is multiplied by the height of the selected font
  165.     and then topspacing and bottomspacing are added. The result is the height
  166.     of a line on the screen (in pixels).
  167.  
  168.     If you wish to give different lines different heights you can add an
  169.     offset in the second word of the linesinfo structure of every line. In
  170.     must cases you will then set the following three options to zero and set
  171.     the whole line height in the linesinfo structure.
  172. */
  173.     short    vw_textheights;
  174.     short    vw_topspacing;
  175.     short    vw_bottomspacing;
  176.  
  177.     short    vw_planes;                        /* number of bitplanes to be
  178.                                                     cleared/scrolled */
  179. /*
  180.     The next variable is used to reserve some space in the window for the
  181.     viewerbar. The two functions behind it are called every time the
  182.     viewerbar should be drawn and removed (free memory etc., you don't have
  183.     to remove the actual graphics).
  184. */
  185.     short    vw_barheight;
  186.     void    (*vw_viewerbar)();
  187.     void    (*vw_remove_vb)();
  188.  
  189. /*
  190.     The next two functions can be used to replace the normal cursright and
  191.     cursleft functions. You can use this the jump the cursor over text
  192.     commands or other places the cursor shouldn't be. Beware that when the
  193.     cursor is in the codebar the normal functions will always be used!
  194. */
  195.     void    (*vw_cursright)();
  196.     void    (*vw_cursleft)();
  197.  
  198. /*
  199.     In vw_font you MUST pass an opened font you wish to you use for
  200.     displaying your text. If you wish to use the default font simply copy the
  201.     font passed to you in the AMIS structure.
  202. */
  203.     struct Font *vw_font;
  204.  
  205. /*
  206.     The next function is used for breaking lines. When this function is
  207.     called you should return the VISIBLE part of the line that is passed to
  208.     you. This means you should filter out everything that will not appear on
  209.     the screen. AMIS will check this line for spaces to break a line. If
  210.     there are spaces on the screen where the line should be broken you sould
  211.     set an '_' in the line you give back instead of a ' '. This way you have
  212.     complete control over where lines may and may not be broken.
  213. */
  214.     void    (*vw_plaintext)();
  215.  
  216. /*
  217.     The next option will be used to make it possible to define different
  218.     functions for keys in different viewers. This isn't completely working
  219.     yet and for now it is best to point to an empty list (you may also pass a
  220.     zero if you wish).
  221. */
  222.     struct List    *vw_keylist;
  223.  
  224. /*
  225.     The next two functions are called every time a file is loaded / saved or
  226.     the user switches to this viewer or an other viewer. You may use these
  227.     functions to filter out text that should not be displayed or something
  228.     like that. Please not that the savefilter should set back all this
  229.     information, otherwise some text might 'get lost' without the user
  230.     knowing about it (not very user friendly, don't you think ?).
  231. */
  232.     void    (*vw_loadfilter)();
  233.     void    (*vw_savefilter)();
  234.  
  235. /*
  236.     The next function is the unload function wish will be called when AMIS is
  237.     quiting. This function allows you to free recources, close fonts, free
  238.     images, etc.
  239. */
  240.     void    (*vw_unload)();
  241.  
  242. /*
  243.     The next option is a pointer to the text you want to be displayed in the
  244.     viewer info requester. Lines can be seperated with a '|' sign.
  245. */
  246.     char    *vw_infotext;
  247.  
  248. /*
  249.     The next function should set all your variables to there initial state.
  250.     (As if a new window was opened without any text in it.)
  251. */
  252.     void    (*vw_clear)();
  253.  
  254. /*
  255.     The next function will be called after the AMIS screen is opened (bootup
  256.     and UnIconify).
  257. */
  258.     void    (*vw_openscreen)();
  259.  
  260. /*
  261.     The next function will be called when the AMIS screen is close (quiting
  262.     and Iconify).
  263. */
  264.     void    (*vw_closescreen)();
  265.  
  266. /*
  267.     The next function is called every time the cursor is drawn, return 1 if
  268.     you rendered the cursor yourself, 0 otherwise.
  269. */
  270.     long    (*vw_drawcurs)();
  271.  
  272. /*
  273.     The next function called when the user tries to insert a character on a
  274.     writeprotected line. Return 1 if it may be inserted, 0 otherwise.
  275. */
  276.     void    (*vw_checkprotection)();
  277.  
  278. /*
  279.     The next function is called when the user gives a Fold command.
  280.     If you want to support folding you should set your fold function here.
  281. */
  282.     void    (*vw_fold)();
  283.  
  284. /*
  285.     The next function is called when the user gives a UnFold command.
  286.     If you want to support folding you should set your unfold function here.
  287. */
  288.     void    (*vw_unfold)();
  289.  
  290. /*
  291.     The next function is called when the user gives a Fold TOGGLE command.
  292.     If you want to support folding you should set your fold toggle function
  293.     here.
  294. */
  295.     void    (*vw_togglefold)();
  296. };
  297.  
  298. /*
  299.     Versions of AMIS that can be given in the ln_type field of the viewer
  300.     structure.
  301. */
  302.  
  303. #define AMIS_0_97        0
  304. #define AMIS_0_98        1        /* also has a vw_clear field. */
  305. #define AMIS_0_99        2        /* also has vw_openscreen and vw_closescreen
  306.                                         fields. */
  307. #define AMIS_1_00        3        /* also has vw_drawcurs, vw_checkprotection,
  308.                                         vw_fold, vw_unfold and vw_togglefold fields.
  309.                                         */
  310. #define AMIS_1_01        4
  311.  
  312. struct AMIS
  313. {
  314.     struct IntuitionBase    *AMIS_IntuitionBase;
  315.     struct GfxBase            *AMIS_GfxBase;
  316.     struct Library            *AMIS_GadBase;
  317.     struct Library            *AMIS_DatatypesBase;
  318.     struct Library            *AMIS_DiskfontBase;
  319.     struct Screen            *AMIS_ScreenBase;
  320.     long                        *AMIS_VisualInfo;
  321.     struct DisplayInfo    *AMIS_DisplayInfo;
  322.     struct ColorMap        *AMIS_ColorMap;
  323.     char                        *AMIS_Flags;
  324.     struct Font                *AMIS_Normal_Font;        /* the default text font */
  325.     char                        *AMIS_PrintBuf;
  326.     struct Catalog            *AMIS_Catalog;
  327.     struct MsgPort            *AMIS_MsgPort;
  328.     void                        *AMIS_ViewerLibBase;
  329.     struct DosLibrary        *AMIS_DOSBase;
  330.     char                        *AMIS_RunTimeFlags;
  331. };
  332.  
  333. #define EFLG_CHANGED        0
  334. #define EFLG_LCHANGED    1
  335. #define EFLG_CURS            2
  336. #define EFLG_CURSMODE    3
  337. #define EFLG_FLASHCURS    4
  338. #define EFLG_HIDE            5
  339. #define EFLG_PLUSSIGN    6
  340. #define EFLG_UNTITLED    7
  341.  
  342. #define EFLG2_MOUSE        0
  343. #define EFLG2_UP            1
  344. #define EFLG2_DOWN        2
  345. #define EFLG2_SELECTED    3
  346. #define EFLG2_SELSTART    4
  347. #define EFLG2_SELEND        5
  348. #define EFLG2_MOUSESEL    6
  349.  
  350. #define EFLG3_MOUSEUP    0
  351. #define EFLG3_MOUSEDOWN    1
  352. #define EFLG3_PROTECT    2
  353. #define EFLG3_MODECHNG    3
  354. #define EFLG3_ICONIFIED    4
  355. #define EFLG3_CODECURS    5
  356. #define EFLG3_NOUPDATE    6
  357. #define EFLG3_REVERT        7
  358.  
  359. #define EFLG4_RESIZED    0
  360. #define EFLG4_TOOLBAR    1
  361. #define EFLG4_VIEWERBAR    2
  362. #define EFLG4_STATUSBAR    3
  363. #define EFLG4_CODEBAR    4
  364. #define EFLG4_OVERWRITE    5
  365. #define EFLG4_LOCKED        6
  366. #define EFLG4_ARRANGING    7
  367.  
  368. #define EFLG5_WORDWRAP    0
  369. #define EFLG5_ANSIBOLD    1
  370. #define EFLG5_NEWFONT    2
  371. #define EFLG5_SMALLCURS    3
  372. #define EFLG5_NOGETWINP    4
  373. #define EFLG5_FASTMODE    5
  374. #define EFLG5_AUTOLINE    6
  375. #define EFLG5_VERTICAL    7
  376.  
  377. #define EFLG6_DRAGNDROP    0
  378. #define EFLG6_LINEPROT    1
  379.  
  380. /* Some settings flags */
  381.  
  382. #define BACKUP_FLAG1        0
  383. #define ICONS_FLAG1        1
  384. #define FLASH_FLAG1        2
  385. #define AUTOIND_FLAG1    3
  386. #define TOOLBAR_FLAG1    4
  387. #define VIEWERBAR_FLAG1    5
  388. #define STATUSBAR_FLAG1    6
  389. #define CODEBAR_FLAG1    7
  390.  
  391. #define CURSWRAP_FLAG2    0
  392. #define FASTMODE_FLAG2    1
  393. #define AUTOLINE_FLAG2    2
  394. #define ANSISHINE_FLAG2    3
  395. #define DRAGNDROP_FLAG2    4
  396. #define NUMERIC_FLAG2    5
  397.  
  398. /*global flags for all files */
  399.  
  400. #define QUIT_FLAG3        0
  401. #define VISIT_FLAG3        1
  402. #define ICONIFIED_FLAG3    2
  403. #define REDO_FLAG3        3
  404. #define JOINUNDO_FLAG3    4
  405. #define CUTBLOCK_FLAG3    5
  406. #define ENDICON_FLAG3    6
  407. #define REDRAW_FLAG3        7
  408.  
  409. #define CURSLINE_FLAG4    0
  410. #define CURSDONE_FLAG4    1
  411. #define CLOSEFONT_FLAG4    2
  412. #define PRIVATE_FLAG4    3
  413. #define ASKPRJ_FLAG4        4
  414. #define MACRO_FLAG4        5
  415. #define MACRO2_FLAG4        6
  416. #define DEFAULT_FLAG4    7
  417.  
  418. #define MACROKEY_FLAG5    0
  419. #define NOPRINT_FLAG5    1
  420. #define SETTINGS_FLAG5    2
  421. #define SETLBUF_FLAG5    3
  422. #define REDRAWING_FLAG5    4
  423. #define CANCEL_FLAG5        5
  424. #define NO_ANSWER_FLAG5    6
  425. #define INIT_FLAG5        7
  426.  
  427. #define BARLABEL_FLAG6    0
  428. #define SUBITEMS_FLAG6    1
  429. #define INIT_CHNG_FLAG6    2
  430. #define COLORS_FLAG6        3
  431. #define NEWPREFS_FLAG6    4
  432. #define MENU_CHNG_FLAG6    5
  433. #define ANSI_UPD_FLAG6    6
  434. #define DRAWDONE_FLAG6    7
  435.  
  436. #define NOSLIDER_FLAG7    0
  437. #define BOOTUP_FLAG7        1
  438. #define SRCPASTE_FLAG7    2
  439.  
  440. #define VFLG1_TOTAL_Y    0
  441. #define VFLG1_TEMP        1        /* Use a temporary rastport (this prevent
  442.                                             blinking graphics, it works the same as a
  443.                                             double buffered screen). */
  444. #define VFLG1_INIT        2        /* Use initializing routine for this viewer */
  445. #define VFLG1_CHAR_STAT    3        /* Use ed_char instead of ed_winpos in
  446.                                             statusbar */
  447. #define VFLG1_PROP        4        /* No fixed with font. */
  448. #define VFLG1_PRINTINIT    5        /* use the display function for initializing. */
  449.  
  450. #define VFLG2_ST_CASE    0
  451. #define VFLG2_PRIVATE2    6
  452. #define VFLG2_PRIVATE    7
  453.  
  454. #define LINEDATA            12
  455.  
  456.  
  457. #pragma libcall ViewerLib InternalCommand        6    0
  458. #pragma libcall ViewerLib CursLeft                c    0
  459. #pragma libcall ViewerLib CursRight                12    0
  460. #pragma libcall ViewerLib Getwinpos                18    0
  461. #pragma libcall ViewerLib GetImage                1e    0
  462. #pragma libcall ViewerLib LoadImage                24    0
  463. #pragma libcall ViewerLib SetViewervar            2a    0
  464. #pragma libcall ViewerLib SetViewervar2        30    0
  465. #pragma libcall ViewerLib WordWrapSaveFilter    36    0
  466. #pragma libcall ViewerLib CursUp                    3c    0
  467. #pragma libcall ViewerLib CursDown                42    0
  468. #pragma libcall ViewerLib CursSOL                48    0
  469. #pragma libcall ViewerLib DoReturn                4e    0
  470. #pragma libcall ViewerLib NewViewerbar            54    0
  471. #pragma libcall ViewerLib BuiltRequester        5a    0
  472. #pragma libcall ViewerLib ShowRequester        60    0
  473. #pragma libcall ViewerLib CloseRequester        66    0
  474. #pragma libcall ViewerLib FreeRequester        6c    0
  475. #pragma libcall ViewerLib FileRequester        72    0
  476. #pragma libcall ViewerLib GetYPos                78    0
  477. #pragma libcall ViewerLib AddLineNode            7e    0
  478. #pragma libcall ViewerLib GetLineNode            84    0
  479.  
  480. ULONG InternalCommand(char *command);
  481.  
  482. ULONG CursLeft(void);
  483. ULONG CursRight(void);
  484. ULONG CursUp(void);
  485. ULONG CursDown(void);
  486. ULONG CursSOL(void);
  487. ULONG CursEOL(void);
  488.  
  489. void GetWinPos(void);
  490.  
  491. ULONG DoReturn(void);
  492.  
  493. void SetViewervar(long var, char *text);
  494. void SetViewervar2(long var, char *text);
  495.  
  496. struct Object *Get_image(char *filename);
  497. struct Object *Load_image(char *filename);
  498.  
  499. void WordWrapSaveFilter(void);
  500.  
  501. void NewViewerBar(void);
  502.  
  503. struct AMIS_Requester *BuiltRequester(struct AMIS_ReqDef *req, struct TagList *tags);
  504. void ShowRequester(struct AMIS_Requester *req);
  505. void CloseRequester(struct AMIS_Requester *req);
  506. void FreeRequester(struct AMIS_Requester *req);
  507.  
  508. long GetYPos(void);
  509.  
  510. struct Node *AddLineNode(long size, long line, long character);
  511. struct Node *GetLineNode(long line, long character);
  512.